package com.hrvsr.common;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.apache.commons.lang3.builder.HashCodeBuilder;

import com.hrvsr.common.consts.HttpMethods;

public class SimplePostRequest extends SimpleGetRequest {
	public SimplePostRequest(String url) {
		super(url);
	}

	private static final long serialVersionUID = 9L;

	private String method = HttpMethods.POST;

	@Override
	public String getMehtod() {
		return method;
	}

	private List<NameValuePair> params = new ArrayList<NameValuePair>();

	public void addParam(String name, String value) {
		params.add(new NameValuePair(name, value));
	}

	public String getMethod() {
		return method;
	}

	public void setMethod(String method) {
		this.method = method;
	}

	public List<NameValuePair> getParams() {
		return params;
	}

	public void setParams(List<NameValuePair> params) {
		this.params = params;
	}

	@Override
	public int hashCode() {
		return new HashCodeBuilder().append(getMehtod()).append(getUrl()).append(params).build();
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (!super.equals(obj))
			return false;
		if (getClass() != obj.getClass())
			return false;
		SimplePostRequest other = (SimplePostRequest) obj;
		if (method == null) {
			if (other.method != null)
				return false;
		} else if (!method.equals(other.method))
			return false;
		if (params == null) {
			if (other.params != null)
				return false;
		} else if (!params.equals(other.params))
			return false;
		return true;
	}

	@Override
	public Iterator<NameValuePair> paramIterator() {
		return params.iterator();
	}

	@Override
	public String toString() {
		return "SimplePostRequest [method=" + method + ", url =" + getUrl() + ", params=" + params + "]";
	}

}
